<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
<html>  
  <head>  
    <title>测试页面</title>  
     <%@ include file="admin/head.jsp"%> 
  </head>  
    
  <body>  
    <a href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onClick="testJSON()">测试Long</a>
     <br/>
    <a href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onClick="testPOST1()">测试POST1</a>
    <br/>
 	<a href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onClick="testPOST2()">测试POST2</a>
 	<br/>
 	<a href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onClick="testPOST3()">测试POST提交@RequestBody获取</a>
 	<br/>
 	<a href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onClick="testPOST4()">测试POST提交@RequestParam获取</a>
 	<br/>
 	<a href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onClick="testPOST5()">测试POST提交@RequestParam获取2</a>
 	<br/>
 	
 	<form id="fm">
   		<table style="margin:0 auto;">
   			<tr>
   				<td>用户名：</td>
   				<td><input type="text" id="userName" name="userName" class="easyui-validatebox tb" data-options="required:true" value="testUser"/></td>
   			</tr>
   			<tr>
   				<td>账号：</td>
   				<td><input type="text" id="userAccount" name="userAccount" value="test"/></td>
   			</tr>
   			<tr>
   				<td>密码：</td>
   				<td><input type="password" id="userPassword" name="userPassword" value="123456"/></td>
   			</tr>
   			<tr>
   				<td>备注：</td>
   				<td><input type="text" id="userRemark" name="userRemark" value="testRemark"/></td>
   			</tr>
   		</table>
   		<div style="text-align:center;">
	        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="save()" style="width:90px">保存</a>
	        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="save2()" style="width:90px">保存2</a>
	        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="save3()" style="width:90px">保存3</a>
	    </div>	
   	</form>
 	
 	
 	<script type="text/javascript">
 	
 		//测试返回json格式
 		function testJSON(){
 			$.ajax({
	 			url:"../test/testJSON",
	 			type:"GET",
	 			async:true,
	 			contentType:"application/x-www-form-urlencoded;charset=utf-8",
	 			success:function(data,textStatus,jqXHR){
	 				console.log(data);
	 			},
	 			 error:function(xhr,textStatus){
	 				 $("#dg").datagrid("loaded"); //移除屏蔽
	 				 $.messager.alert('操作提示', '请求出错！', 'error');
	 			 }
	 		});
 		}
 	
 	
	 	//测试函数
	 	function testPOST1(){
	 		$.ajax({
	 			url:"../test/getJSONData",
	 			type:"POST",
	 			async:true,
	 			contentType:"application/json",
	 			data:{
	 				id : "123",
	 				name : ""
	 			},
	 			dataType:'json',
	 			success:function(data,textStatus,jqXHR){
	 				console.log(data);
	 			},
	 			 error:function(xhr,textStatus){
	 				 $.messager.alert('操作提示', '请求出错！', 'error');
	 			 }
	 		});
	 		
	 	}
	
	 	//测试函数
	 	function testPOST2(){
	 		$.ajax({
	 			url:"../test/getJSONData",
	 			type:"POST",
	 			async:true,
	 			contentType:"application/x-www-form-urlencoded;charset=utf-8",
	 			data:{
	 				id : "123",
	 				name : ""
	 			},
	 			dataType:'json',
	 			success:function(data,textStatus,jqXHR){
	 				console.log(data);
	 			},
	 			 error:function(xhr,textStatus){
	 				 $.messager.alert('操作提示', '请求出错！', 'error');
	 			 }
	 		});
	 	}
	 	
	 	//测试函数
	 	function testPOST3(){
	 		var formData = { 
	 				id:123, 
	 				name:""
	 		};
	 		$.ajax({
	 			url:"../test/getJSONData2",
	 			type:"POST",
	 			async:true,
	 			contentType:"application/json",
	 			data:JSON.stringify(formData),
	 			dataType:'json',
	 			success:function(data,textStatus,jqXHR){
	 				console.log(data);
	 			},
	 			 error:function(xhr,textStatus){
	 				 $.messager.alert('操作提示', '请求出错！', 'error');
	 			 }
	 		});
	 	}
	 	
	 	//测试函数
	 	function testPOST4(){
	 		var formData = { 
	 				data:"测试"
	 		};
	 		$.ajax({
	 			url:"../test/getJSONData4",
	 			type:"POST",
	 			async:true,
	 			contentType:"application/x-www-form-urlencoded;charset=utf-8",
	 			data:{
	 				data:"测试"
	 			},
	 			dataType:'json',
	 			success:function(data,textStatus,jqXHR){
	 				console.log(data);
	 			},
	 			error:function(xhr,textStatus){
	 				$.messager.alert('操作提示', '请求出错！', 'error');
	 			}
	 		});
	 	}
	 	
	 	//测试函数
	 	function testPOST5(){
	 		$.ajax({
	 			url:"../test/getJSONData5",
	 			type:"POST",
	 			async:true,
	 			contentType:"application/x-www-form-urlencoded;charset=utf-8",
	 			data:{
	 				data:"测试"
	 			},
	 			dataType:'json',
	 			success:function(data,textStatus,jqXHR){
	 				console.log(data);
	 			},
	 			error:function(xhr,textStatus){
	 				$.messager.alert('操作提示', '请求出错！', 'error');
	 			}
	 		});
	 	}
	 	
	 	//测试表单保存
	 	function save(){
	 		console.log($("#fm").serialize());
	 		console.log(JSON.stringify($("#fm").serialize()));
	 		$.ajax({
	 			url:"../test/getJSONData",
	 			type:"POST",
	 			async:true,
	 			data:$("#fm").serialize(),
	 			dataType:'json',
	 			success:function(data,textStatus,jqXHR){
	 				console.log(data);
	 			},
	 			 error:function(xhr,textStatus){
	 				 $.messager.alert('操作提示', '请求出错！', 'error');
	 			 }
	 		});
	 	}
	 	
	 	//测试表单保存
	 	function save2(){
	 		$.ajax({
	 			url:"../test/getJSONData2",
	 			type:"POST",
	 			async:true,
	 			contentType:"application/json",
	 			data:$("#fm").serialize(),
	 			dataType:'json',
	 			success:function(data,textStatus,jqXHR){
	 				console.log(data);
	 			}
	 		});
	 	}
	 	
	 	//测试表单保存
	 	function save3(){
	 		$.ajax({
	 			url:"../test/getJSONData3",
	 			type:"POST",
	 			async:true,
	 			contentType:"application/x-www-form-urlencoded;charset=utf-8",//原生的声明，所有标签都可以被拦截，但是如果用form表单系列化方法法提交，则要用@RequestParam来获取参数，使用@RequestBody会报错
	 			//contentType:"application/json",//会无效，因为SpringMvc要使用@RequestBody才能拦截获取参数
	 			data:$("#fm").serialize(),
	 			success:function(data,textStatus,jqXHR){
	 				console.log(data);
	 			}
	 		});
	 	}
 	</script>
  </body>  
</html>  